package com.jams.goodox.activity.serve.meet;

import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.jams.goodox.R;
import com.jams.goodox.entity.MeetSessionItemBean;
import com.jams.goodox.utils.StringUtils;
import com.yanzhenjie.permission.AndPermission;
import com.yanzhenjie.permission.PermissionNo;
import com.yanzhenjie.permission.PermissionYes;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by jams_zhen on 2017/5/9.
 */

public class MeetSessionCompanyDialogActivity extends Activity {

    @Bind(R.id.tx_company)
    TextView txCompany;
    @Bind(R.id.tx_session_time)
    TextView txSessionTime;
    @Bind(R.id.tx_session_people)
    TextView txSessionPeople;

    private MeetSessionItemBean meetSessionTime;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_meet_company_session);
        ButterKnife.bind(this);
        Window win = this.getWindow();

        win.getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams lp = win.getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        win.setAttributes(lp);

        initData();
    }

    private void initData() {
        meetSessionTime = (MeetSessionItemBean) getIntent().getSerializableExtra("sessionBean");
        txCompany.setText(meetSessionTime.getEnterpriseName());
        txSessionTime.setText("预定时间：" + meetSessionTime.getSessionDurationTime());
//        txSessionPeople.setText("预订人：" + meetSessionTime.getE());
    }

    @OnClick({R.id.dialog_close, R.id.frame_phone})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.dialog_close:
                finish();
                break;
            case R.id.frame_phone:
                AndPermission.with(this)
                        .requestCode(100)
                        .callback(this)
                        .permission(Manifest.permission.CALL_PHONE)
                        .start();
                break;
        }
    }

    @PermissionYes(100)
    private void getPhone() {
        String phoneNum = StringUtils.getPhoneStr(meetSessionTime.getOrderId());
        if (TextUtils.isEmpty(phoneNum)) return;
        Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNum));
        startActivity(intent);
    }

    @PermissionNo(100)
    private void noCallPhone(List<String> grantedPermissions) {

    }

}
